package com.huawei.hms.support.common;

import android.app.Activity;
import android.app.Application;
import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Bundle;
import com.huawei.hms.support.log.HMSLog;
import com.huawei.hms.utils.StringUtil;
import java.lang.ref.WeakReference;

public final class ActivityMgr implements ActivityLifecycleCallbacks {
    public static final ActivityMgr INST = new ActivityMgr();
    private WeakReference<Activity> a;

    private ActivityMgr() {
    }

    public void init(Application application) {
        HMSLog.d("ActivityMgr", "init");
        if (application == null) {
            HMSLog.w("ActivityMgr", "init failed for app is null");
            return;
        }
        application.unregisterActivityLifecycleCallbacks(INST);
        application.registerActivityLifecycleCallbacks(INST);
    }

    public Activity getCurrentActivity() {
        if (this.a == null) {
            return null;
        }
        return (Activity) this.a.get();
    }

    public void onActivityCreated(Activity activity, Bundle bundle) {
        HMSLog.d("ActivityMgr", "onCreated:" + StringUtil.objDesc(activity));
        this.a = new WeakReference(activity);
    }

    public void onActivityStarted(Activity activity) {
        HMSLog.d("ActivityMgr", "onStarted:" + StringUtil.objDesc(activity));
        this.a = new WeakReference(activity);
    }

    public void onActivityResumed(Activity activity) {
        HMSLog.d("ActivityMgr", "onResumed:" + StringUtil.objDesc(activity));
        this.a = new WeakReference(activity);
    }

    public void onActivityPaused(Activity activity) {
    }

    public void onActivityStopped(Activity activity) {
    }

    public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
    }

    public void onActivityDestroyed(Activity activity) {
    }
}
